// import { getAllRoleList, isAccountExist } from '@/api/demo/system';
import { BasicColumn, FormSchema } from '@/components/Table';
import { Tinymce } from '@/components/Tinymce';
import { h, ref, onMounted } from 'vue';
import { getItemApi } from '@/api/demo/code';
import { getUserMapAPI } from '@/api/demo/device';
import { useI18n } from "@/hooks/web/useI18n";

const { t } = useI18n();
/**
 * transform mock data
 * {
 *  0: '华东分部',
 * '0-0': '华东分部-研发部'
 * '0-1': '华东分部-市场部',
 *  ...
 * }
 */
// export const deptMap = (() => {
//   const pDept = ['华东分部', '华南分部', '西北分部'];
//   const cDept = ['研发部', '市场部', '商务部', '财务部'];

//   return pDept.reduce((map, p, pIdx) => {
//     map[pIdx] = p;

//     cDept.forEach((c, cIndex) => (map[`${pIdx}-${cIndex}`] = `${p}-${c}`));

//     return map;
//   }, {});
// })();
//表头数据

let options = ref([]);
let userList = [];

async function getItem() {
  let data = await getItemApi();
  options.value = data.data.map((item) => ({
    value: item.code,
    label: item.name,
  }));
}

async function getUserMap() {
  let value = await getUserMapAPI();
  userList = value.data;
}
getUserMap();
// 在组件挂载时调用 getItem
onMounted(() => {
  getItem();
});
export const columns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 120,
  },
  {
    title: t('sys.code.title'),
    dataIndex: 'code',
    width: 120,
  },
  {
    title: t('sys.informaionMatchaing.columns.createTime'),
    dataIndex: 'createTime',
    width: 120,
  },
  {
    title: t('sys.code.columns.buyer'),
    dataIndex: 'type',
    width: 120,
  },
  {
    title: t('sys.code.columns.butime'),
    dataIndex: 'value',
    width: 120,
    customRender: ({ text, record }) => {
      let formattedRemark = record.value;
      if (record.type === 'day') {
        formattedRemark += t('sys.configuration.day');
      } else if (record.type === 'month') {
        formattedRemark += t('sys.configuration.month');
      } else if (record.type === 'quarter') {
        formattedRemark += t('sys.configuration.quarter');
      } else {
        formattedRemark += t('sys.configuration.year');
      }
      return h('span', formattedRemark);
    },
  },
  {
    title: t('sys.code.columns.status'),
    dataIndex: 'status',
    width: 120,
    customRender: ({ text }) => {
      if (text === 0) {
        return t('sys.code.columns.notBound');
      } else if (text === 1) {
        return t('sys.code.columns.boundAlready');
      } else {
        return t('sys.code.columns.unknownState');
      }
    },
  },
  {
    title: t('sys.code.columns.account'),
    dataIndex: 'createUser',
    width: 120,
    customRender: ({ text }) => {
      const user = userList.find((u) => u.value == text);
      return user ? user.label : '-';
    },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'type',
    component: 'Select',
    label: t('sys.code.columns.buyer'),
    rules: [{ required: true }],
    componentProps: {
      options: [],
      placeholder: '请选择',
    },
  },
  {
    field: 'value',
    component: 'Input',
    label: t('sys.code.columns.butime'),
    defaultValue: '',
    rules: [{ required: true }],
  },
];

//基础字段
export const accountFormSchemaFields: FormSchema[] = [
  {
    field: 'title',
    component: 'Input',
    label: t('sys.video.columns.submitTitel'),
    defaultValue: '',

    rules: [{ required: true }],
  },
  {
    field: 'title',
    component: 'RadioGroup',
    label: t('sys.video.columns.isPhoto'),
    defaultValue: '',
    componentProps: {
      options: [
        {
          label: t('sys.configuration.YES'),
          value: '1',
        },
        {
          label: t('sys.configuration.NO'),
          value: '2',
        },
      ],
    },

    rules: [{ required: true }],
  },
  {
    field: 'title',
    component: 'RadioGroup',
    label: t('sys.video.columns.submitType'),
    defaultValue: '',
    rules: [{ required: true }],
    componentProps: {
      options: [
        {
          label: t('sys.video.columns.trueType'),
          value: '1',
        },
        {
          label: t('sys.video.columns.selectType'),
          value: '2',
        },
        {
          label: t('sys.video.columns.selectListType'),
          value: '3',
        },
      ],
    },
  },
  {
    field: 'title',
    component: 'Input',
    label: t('sys.video.columns.configurationOptions'),
    defaultValue: '',

    rules: [{ required: true }],
  },
];
